package acwing._1_1AlgorithmBasic._6Greedy;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._1_1AlgorithmBasic._6Greedy
 * @File : Q0125.java
 * @Author : WangRuoyu
 * @Date : 2023/4/7 10:57
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Q0125 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] words = br.readLine().split(" ");
        int n = Integer.parseInt(words[0]);
        long[][] a = new long[n][2];

        for (int i = 0; i < n; ++i) {
            words = br.readLine().split(" ");
            a[i][0] = Long.parseLong(words[0]);
            a[i][1] = Long.parseLong(words[1]);
        }

        Arrays.sort(a, (o1, o2) -> Long.compare(o1[0] + o1[1], o2[0] + o2[1]));

        long res = Integer.MIN_VALUE;
        long[] s = new long[n + 1];
        for (int i = 0; i < n; ++i) {
            res = Math.max(res, s[i] - a[i][1]);
            s[i + 1] = s[i] + a[i][0];
        }

        System.out.println(res);
    }
}

